package org.mobilesynergies.epic.service.java;

import org.mobilesynergies.epic.client.EpicCommand;
import org.mobilesynergies.epic.client.parameter.BooleanParameter;
import org.mobilesynergies.epic.client.parameter.FloatParameter;
import org.mobilesynergies.epic.client.parameter.IntParameter;
import org.mobilesynergies.epic.client.parameter.ParameterMap;
import org.mobilesynergies.epic.client.parameter.StringParameter;

public class MyMultiStageCommand extends EpicCommand{

		@Override
	public String getHumanReadableName() {
		return "Super cool multi stage command";
	}

	@Override
	public String getId() {
		return "MyMultiStageCommand";
	}

	@Override
	public boolean hasPermission(String jid) {
		return true;
	}

	@Override
	public void cancel() {
		System.out.println("cancel"+ "  ("+getCurrentStage()+")");

	}

	@Override
	public void finalize(ParameterMap response) {
		System.out.println("finalize"+ "  ("+getCurrentStage()+")");
		if (getCurrentStage()==3) { 
			if(response.containsKey("lalala")){
				System.out.println("lalala: "+ String.valueOf(response.getString("lalala")));
			}
		} else {
			System.out.println("didn't expect this to happen (fialize was called in an unexpected stage)");
		}

	}

	@Override
	public ParameterMap initialize() {
		System.out.println("initialize"+ "  ("+getCurrentStage()+")");
		ParameterMap map = new ParameterMap();

		IntParameter intparam = new IntParameter(10, 0, 100, 1); 
		FloatParameter floatparam = new FloatParameter(5, 0, 10, 0.01f);
		BooleanParameter boolparam = new BooleanParameter(true); 
		map.putParameter("my int param", intparam);
		map.putParameter("my float param", floatparam);
		map.putParameter("my boolean param", boolparam);
		map.putString("my simple string param", "this is the value of my simple string param");
		map.putParameter("my string param", new StringParameter("this is the value of my string param"));
		map.putInt("my simple int param", 0);
		map.putBoolean("my simple bool param", false);
		return map;

	}

	@Override
	public boolean isLastStage() {
		System.out.println("isLastStage "+ " ("+getCurrentStage()+")");	
		if(getCurrentStage() < 2){
			return false;
		}
		return true;
	}

	@Override
	public ParameterMap nextStage(ParameterMap response) {
		

		
		System.out.println("nextStage: stage "+ "  ("+getCurrentStage()+")" );

		ParameterMap parametersNextStage = new ParameterMap();

		if(getCurrentStage()==1) {
			if(response.containsKey("my int param")){
				System.out.println("my int param: "+ String.valueOf(response.getInt("my int param")));
			}
			if(response.containsKey("my float param")){
				System.out.println("my float param: "+ String.valueOf(response.getFloat("my float param")));
			}
			if(response.containsKey("my boolean param")){
				System.out.println("my boolean param: "+ String.valueOf(response.getBoolean("my boolean param")));
			}
			if(response.containsKey("my simple string param")){
				System.out.println("my simple string param: "+ String.valueOf(response.getString("my simple string param")));
			}
			if(response.containsKey("my string param")){
				System.out.println("my string param: "+ String.valueOf(response.getString("my string param")));
			}
			if(response.containsKey("my simple int param")){
				System.out.println("my simple int param: "+ String.valueOf(response.getInt("my simple int param")));
			}
			if(response.containsKey("my simple bool param")){
				System.out.println("my simple bool param: "+ String.valueOf(response.getBoolean("my simple bool param")));
			}
			if(response.containsKey("bool param second stage")){
				System.out.println("bool param second stage: "+ String.valueOf(response.getBoolean("bool param second stage")));
			}

			parametersNextStage.putBoolean("bool param second stage", false);
			parametersNextStage.putParameter("int param second stage", new IntParameter(0, -10, 10, 1));
			parametersNextStage.putParameter("float param second stage", new FloatParameter(-200, -10, 10, 5));

		} else if (getCurrentStage()==2) {

			if(response.containsKey("bool param second stage")){
				System.out.println("bool param second stage: "+ String.valueOf(response.getBoolean("bool param second stage")));
			}
			if(response.containsKey("float param second stage")){
				System.out.println("float param second stage: "+ String.valueOf(response.getFloat("float param second stage")));
			}
			if(response.containsKey("int param second stage")){
				System.out.println("int param second stage: "+ String.valueOf(response.getInt("int param second stage")));
			}

			parametersNextStage.putString("lalala", "last stage string");


		} else if (getCurrentStage()==3) { 
			if(response.containsKey("lalala")){
				System.out.println("lalala: "+ String.valueOf(response.getString("lalala")));
			}
		} else {
			System.out.println("didn't expect this to happen (other stage than expected)");
		}


		return parametersNextStage;

	}

	@Override
	public void previousStage() {
		System.out.println("previousStage"+ "  ("+getCurrentStage()+")");

	}


}